﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using nkstdgia.common.ThamDinhGia.BusinessObjects;

namespace nkstdgia.common.ThamDinhGia.DataAccess
{
    public class DUONG_KHAO_SATDA
    {
        #region ***** Init Methods *****

        public DUONG_KHAO_SATDA()
        {
        }

        #endregion ***** Init Methods *****

        #region ***** Get Methods *****

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public DUONG_KHAO_SAT Populate(IDataReader myReader)
        {
            DUONG_KHAO_SAT obj = new DUONG_KHAO_SAT();
            obj.MA_DKS = (Int64)myReader["MA_DKS"];
            obj.QUAN = (Int64)myReader["QUAN"];
            obj.PHUONG = (Int64)myReader["PHUONG"];
            obj.DUONG = myReader["DUONG"] != DBNull.Value ? (string)myReader["DUONG"] : "";
            obj.DOAN_DUONG = myReader["DOAN_DUONG"] != DBNull.Value ? (string)myReader["DOAN_DUONG"] : "";
            obj.NGAY_KHOI_TAO = myReader["NGAY_KHOI_TAO"] != DBNull.Value ? (DateTime)myReader["NGAY_KHOI_TAO"] : new DateTime(); ;
            obj.ACTIVE_FLAG = myReader["ACTIVE_FLAG"] != DBNull.Value ? (string)myReader["ACTIVE_FLAG"] : "N";
            return obj;
        }

        /// <summary>
        /// Get DUONG_KHAO_SAT by ma_dks
        /// </summary>
        /// <param name="ma_dks">MA_DKS</param>
        /// <returns>DUONG_KHAO_SAT</returns>
        public DUONG_KHAO_SAT GetByMA_DKS(Int64 ma_dks)
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_DUONG_KHAO_SAT_GetByMA_DKS", Data.CreateParameter("MA_DKS", ma_dks)))
            {
                if (reader.Read())
                {
                    return Populate(reader);
                }
                return null;
            }
        }

        /// <summary>
        /// Get all of DUONG_KHAO_SAT
        /// </summary>
        /// <returns>List<<DUONG_KHAO_SAT>></returns>
        public List<DUONG_KHAO_SAT> GetList()
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_DUONG_KHAO_SAT_Get4Export"))
            {
                List<DUONG_KHAO_SAT> list = new List<DUONG_KHAO_SAT>();
                while (reader.Read())
                {
                    list.Add(Populate(reader));
                }
                return list;
            }
        }

        /// <summary>
        /// Get DataSet of DUONG_KHAO_SAT
        /// </summary>
        /// <returns>DataSet</returns>
        public DataSet GetDataSet()
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_DUONG_KHAO_SAT_Get");
        }

        /// <summary>
        /// Get all of DUONG_KHAO_SAT paged
        /// </summary>
        /// <param name="recperpage">record per page</param>
        /// <param name="pageindex">page index</param>
        /// <returns>List<<DUONG_KHAO_SAT>></returns>
        public List<DUONG_KHAO_SAT> GetListPaged(int recperpage, int pageindex)
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_DUONG_KHAO_SAT_GetPaged"
                            , Data.CreateParameter("recperpage", recperpage)
                            , Data.CreateParameter("pageindex", pageindex)))
            {
                List<DUONG_KHAO_SAT> list = new List<DUONG_KHAO_SAT>();
                while (reader.Read())
                {
                    list.Add(Populate(reader));
                }
                return list;
            }
        }

        /// <summary>
        /// Get DataSet of DUONG_KHAO_SAT paged
        /// </summary>
        /// <param name="recperpage">record per page</param>
        /// <param name="pageindex">page index</param>
        /// <returns>DataSet</returns>
        public DataSet GetDataSetPaged(int recperpage, int pageindex)
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_DUONG_KHAO_SAT_GetPaged"
                            , Data.CreateParameter("recperpage", recperpage)
                            , Data.CreateParameter("pageindex", pageindex));
        }

        #endregion ***** Get Methods *****

        #region ***** Add Update Delete Methods *****

        /// <summary>
        /// Add a new DUONG_KHAO_SAT within DUONG_KHAO_SAT database table
        /// </summary>
        /// <param name="obj">DUONG_KHAO_SAT</param>
        /// <returns>key of table</returns>
        public long Add(DUONG_KHAO_SAT obj)
        {
            DbParameter parameterItemID = Data.CreateParameter("MA_DKS", obj.MA_DKS);
            parameterItemID.Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_DUONG_KHAO_SAT_Add"
                            , parameterItemID
                            , Data.CreateParameter("QUAN", obj.QUAN)
                            , Data.CreateParameter("PHUONG", obj.PHUONG)
                            , Data.CreateParameter("DUONG", obj.DUONG)
                            , Data.CreateParameter("DOAN_DUONG", obj.DOAN_DUONG)
                            , Data.CreateParameter("NGAY_KHOI_TAO", obj.NGAY_KHOI_TAO)
                            , Data.CreateParameter("ACTIVE_FLAG", obj.ACTIVE_FLAG)
            );
            return (long)parameterItemID.Value;
        }

        /// <summary>
        /// updates the specified DUONG_KHAO_SAT
        /// </summary>
        /// <param name="obj">DUONG_KHAO_SAT</param>
        /// <returns></returns>
        public void Update(DUONG_KHAO_SAT obj)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_DUONG_KHAO_SAT_Update"
                            , Data.CreateParameter("MA_DKS", obj.MA_DKS)
                            , Data.CreateParameter("QUAN", obj.QUAN)
                            , Data.CreateParameter("PHUONG", obj.PHUONG)
                            , Data.CreateParameter("DUONG", obj.DUONG)
                            , Data.CreateParameter("DOAN_DUONG", obj.DOAN_DUONG)
                            , Data.CreateParameter("NGAY_KHOI_TAO", obj.NGAY_KHOI_TAO)
                            , Data.CreateParameter("ACTIVE_FLAG", obj.ACTIVE_FLAG)
            );
        }

        /// <summary>
        /// Delete the specified DUONG_KHAO_SAT
        /// </summary>
        /// <param name="ma_dks">MA_DKS</param>
        /// <returns></returns>
        public void Delete(Int64 ma_dks)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_DUONG_KHAO_SAT_Delete", Data.CreateParameter("MA_DKS", ma_dks));
        }

        #endregion ***** Add Update Delete Methods *****
    }
}